import path from 'path'

export default {
  db: {
    mongodb: {
      uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/live-chat-dev',
      options: {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        // 连接池配置
        poolSize: 10,
        // 超时设置
        connectTimeoutMS: 10000,
        socketTimeoutMS: 45000,
      },
    },
    redis: {
      host: process.env.REDIS_HOST || 'localhost',
      port: parseInt(process.env.REDIS_PORT || '6379'),
      username: process.env.REDIS_USERNAME,
      password: process.env.REDIS_PASSWORD,
      // 集群配置
      cluster: {
        enabled: false,
        nodes: [],
      },
      // 哨兵配置
      sentinel: {
        enabled: false,
        masterName: 'mymaster',
        nodes: [],
      },
    },
  },
  jwt: {
    secret: process.env.JWT_SECRET || 'dev-secret-key',
    expiresIn: '7d',
  },
  server: {
    port: parseInt(process.env.PORT || '3000'),
    host: process.env.HOST || 'localhost',
    // 开发调试
    debug: {
      enabled: true,
      level: 'debug',
      // Chrome DevTools配置
      inspector: {
        enabled: true,
        port: 9229,
      },
    },
    // 热重载
    hotReload: {
      enabled: true,
      extensions: ['.ts', '.json'],
    },
  },
  media: {
    rtmp: {
      port: parseInt(process.env.RTMP_PORT || '1935'),
      chunk_size: 60000,
      gop_cache: true,
      ping: 30,
      ping_timeout: 60,
      // RTMP推流鉴权
      auth: {
        enabled: true,
        key: process.env.RTMP_AUTH_KEY || 'dev-rtmp-key',
      },
    },
    http: {
      port: parseInt(process.env.HTTP_PORT || '8000'),
      allow_origin: '*',
      mediaroot: path.join(process.cwd(), process.env.MEDIA_ROOT || 'media'),
      // HTTP-FLV拉流
      flv: {
        enabled: true,
        path: '/live',
      },
      // HLS拉流
      hls: {
        enabled: true,
        path: '/hls',
        fragment: '2s',
        playlist: '10s',
      },
    },
    // 录制配置
    recording: {
      enabled: true,
      path: path.join(process.cwd(), 'recordings'),
      format: 'flv',
      // 自动切片
      segment: {
        enabled: true,
        duration: 3600, // 1小时切片
      },
    },
  },
  client: {
    url: process.env.CLIENT_URL || 'http://localhost:3000',
  },
  stream: {
    keySecret: process.env.STREAM_KEY_SECRET || 'dev-stream-key-secret',
  },
  tools: {
    vscode: {
      extensions: [
        'dbaeumer.vscode-eslint',
        'esbenp.prettier-vscode',
        'eamodio.gitlens',
        'formulahendry.code-runner',
        'ms-ceintl.vscode-language-pack-zh-hans',
        'humao.rest-client', // REST Client
        'mhutchie.git-graph', // Git Graph
        'streetsidesoftware.code-spell-checker', // 拼写检查
        'wayou.vscode-todo-highlight', // TODO高亮
      ],
      settings: {
        'files.eol': '\r\n',
        'files.encoding': 'utf8',
        'editor.tabSize': 2,
        'editor.formatOnSave': true,
        // 中文配置
        'editor.fontFamily': "'Microsoft YaHei Mono', Consolas, 'Courier New', monospace",
        'terminal.integrated.shell.windows': 'C:\\Windows\\System32\\cmd.exe',
      },
    },
    dependencies: {
      // 包管理器配置
      npm: {
        registry: 'https://registry.npmmirror.com', // 淘宝镜像
        disturl: 'https://npmmirror.com/mirrors/node',
        cache: 'D:\\livechat\\cache\\npm',
      },
      // Git配置
      git: {
        repository: {
          type: 'gitee',
          url: 'https://gitee.com/example/livechat',
          branch: 'develop',
        },
        // 提交规范
        commit: {
          template: 'D:\\livechat\\templates\\git-commit.txt',
          lint: {
            enabled: true,
            config: 'D:\\livechat\\config\\commitlint.config.js',
          },
        },
      },
    },
  },
  testing: {
    unit: {
      framework: 'jest',
      coverage: {
        enabled: true,
        threshold: {
          statements: 80,
          branches: 70,
          functions: 80,
          lines: 80,
        },
      },
      reports: {
        path: 'D:\\livechat\\reports\\unit',
        format: ['html', 'json'],
      },
    },
    api: {
      framework: 'supertest',
      environment: {
        baseUrl: 'http://localhost:3000',
        timeout: 5000,
        headers: {
          'Content-Type': 'application/json',
        },
      },
      mock: {
        enabled: true,
        port: 3001,
        data: 'D:\\livechat\\test\\mock',
      },
    },
    stress: {
      tool: 'artillery',
      scenarios: {
        liveRoom: {
          duration: 300,
          arrivalRate: 10,
          maxVirtualUsers: 1000,
        },
        payment: {
          duration: 180,
          arrivalRate: 5,
          maxVirtualUsers: 500,
        },
      },
      reports: {
        path: 'D:\\livechat\\reports\\stress',
        format: ['html', 'json'],
      },
    },
  },
  documentation: {
    api: {
      tool: 'swagger',
      output: 'D:\\livechat\\docs\\api',
      ui: {
        enabled: true,
        port: 3002,
        title: '直播平台API文档',
      },
    },
    dev: {
      tool: 'vuepress',
      source: 'D:\\livechat\\docs\\dev',
      output: 'D:\\livechat\\docs\\dist',
      structure: {
        guide: '开发指南',
        api: 'API参考',
        deploy: '部署文档',
        faq: '常见问题',
      },
    },
    generation: {
      enabled: true,
      tools: {
        typescript: 'typedoc',
        database: 'pdman',
        api: 'swagger-jsdoc',
      },
      output: 'D:\\livechat\\docs\\generated',
    },
  },
  standards: {
    code: {
      eslint: {
        config: 'D:\\livechat\\config\\eslint.config.js',
        ignore: 'D:\\livechat\\.eslintignore',
      },
      prettier: {
        config: 'D:\\livechat\\config\\prettier.config.js',
      },
    },
    typescript: {
      strict: true,
      paths: {
        '@/*': ['src/*'],
      },
      types: ['node', 'jest', 'express'],
    },
  },
}
